{include file="pageheader_erp.htm"}

{insert_scripts files="../js/jquery.1.3.2.js"}

<!-- start warehouse list -->
 <div class="list-div" id="listDiv">
<table  cellpadding="3" cellspacing="1">
  <tr>
    <th  width="5%">{$lang.erp_warehouse_id}</th>
    <th width="10%">{$lang.erp_warehouse_name}</th>	
	<th>{$lang.erp_warehouse_description}</th>
 	<th width="10%">{$lang.erp_warehouse_administer}</th>	
	<th width="8%">{$lang.erp_is_valid}</th>	
	<th width="10%">{$lang.erp_operation}</th>
  </tr>
  {foreach from=$warehouse_info key=key item=warehouse_info}
  <tr>
  	<td align="center">{$warehouse_info.warehouse_id}</td>
	<td>{$warehouse_info.name}</td>  
	<td>
		<span id="span_description_{$warehouse_info.warehouse_id}">{$warehouse_info.description}</span>
		<input id="input_description_{$warehouse_info.warehouse_id}" size="50" style="display:none" value="{$warehouse_info.description}"/>
	</td>  
	<td>
		<span id="span_admin_{$warehouse_info.warehouse_id}">{$warehouse_info.admin_name}</span>
		{if $admins}
		<select id="select_admin_name_{$warehouse_info.warehouse_id}" style="display:none;">
			{foreach from=$admins item=admin}
				<option value='{$admin.user_id}' {if $warehouse_info.admin_id eq $admin.user_id}selected='selected'{/if}>{$admin.user_name}</option>
			{/foreach}
		</select>
		{/if}
	</td> 
	
	<td align="center"><span id="is_valid_{$warehouse_info.warehouse_id}" style="cursor:pointer;color:{if $warehouse_info.is_valid eq 1}red;{else}black;{/if}">{if $warehouse_info.is_valid eq 1}{$lang.erp_yes}{else}{$lang.erp_no}{/if}</span></td>  
	<td align="center">
		<a href="javascript:edit_it({$warehouse_info.warehouse_id})">{$lang.erp_operation_edit}</a>
		&nbsp;&nbsp;
		{if $key neq 0}<a href="javascript:delete_it({$warehouse_info.warehouse_id})">{$lang.erp_operation_delete}</a>{/if}
	</td>    
  </tr>  
  {foreachelse}
  <tr><td class="no-records" colspan="6">{$lang.no_records}</td></tr>
  {/foreach}
</table>
</div>
<!-- end warehouse list -->

{literal}
<script language="JavaScript">
	
	function delete_it(warehouse_id)
	{
		function deleteWarehouseResponse(res)
		{
			if(res.error==3)
			{
				alert(res.message);
				window.document.location.reload();
			}
			else if(res.error==0){
				window.document.location.reload();
			}
			else{
				alert(res.message);
			}
		}
	
		if(confirm('{$lang.erp_sure_to_delete}')){
			Ajax.call('erp_warehouse.php?act=delete_warehouse', 'warehouse_id=' + warehouse_id, deleteWarehouseResponse, 'POST', 'JSON');
		}		
	}
	
	function edit_it(warehouse_id)
	{
		$("#span_description_"+warehouse_id).hide();
		$("#input_description_"+warehouse_id).show();
		$("#span_admin_"+warehouse_id).hide();
		$("#select_admin_name_"+warehouse_id).show();
	}
	
   $(document).ready(function(){
   		
		//设置是否有效
   		$("span[id^='is_valid_']").click(function(){
			var $select_item=$(this);
			var warehouse_id=$select_item.attr('id');
			warehouse_id=warehouse_id.substr('is_valid_'.length,warehouse_id.length-'is_valid_'.length);
			
			function changeIsValidResponse(res)
			{
				if(res.error==0 && res.is_valid==1)
				{
					$select_item.css('color','red');
					$select_item.text('{$lang.erp_yes}');
					//alert(res.message);
				}
				else if(res.error==0 && res.is_valid===0)
				{
					$select_item.css('color','black');
					$select_item.text('{$lang.erp_no}');
					//alert(res.message);
				}
				else{
					
					alert(res.message);
				}
			}
			
			Ajax.call('erp_warehouse.php?act=change_is_valid', 'warehouse_id=' + warehouse_id, changeIsValidResponse, 'POST', 'JSON');
		});
		
		//更改仓库描述
		$("span[id^='span_description_']").css('cursor','pointer');
		$("span[id^='span_description_']").mouseover(function(){
			$(this).css('color','red');
		});
		$("span[id^='span_description_']").mouseout(function(){
			$(this).css('color','black');
		});
		$("span[id^='span_description_']").click(function(){
			var warehouse_id=$(this).attr('id');
			warehouse_id=warehouse_id.substr('span_description_'.length,warehouse_id.length-'span_description_'.length);
			$("#input_description_"+warehouse_id).show();
			$(this).hide();
		});		
		
		$("input[id^='input_description_']").blur(function(){
			var warehouse_id=$(this).attr('id');
			warehouse_id=warehouse_id.substr('input_description_'.length,warehouse_id.length-'input_description_'.length);
			
			new_description=$(this).attr('value');
	
			if(confirm('{$lang.erp_warehouse_sure_to_change_description}'))
			{
				Ajax.call('erp_warehouse.php?act=change_description', 'warehouse_id='+warehouse_id+'&new_description='+new_description, changeDescription, 'POST', 'JSON');
			}
			else{
				$("#input_description_"+warehouse_id).hide();
				$("#input_description_"+warehouse_id).attr('value',$("#span_description_"+warehouse_id).text());
				$("#span_description_"+warehouse_id).show();
			}					
			
			
			function changeDescription(res)
			{
				if(res.error!=0)
				{
					alert(res.message);
				}
				else{
					$("#input_description_"+warehouse_id).hide();
					$("#span_description_"+warehouse_id).text(new_description);
					$("#span_description_"+warehouse_id).show();					
				}
			}
		});
		//更改仓管员
		$("span[id^='span_admin_']").css('cursor','pointer');
		
		$("span[id^='span_admin_']").mouseover(function(){
			$(this).css('color','red');
		});
		$("span[id^='span_admin_']").mouseout(function(){
			$(this).css('color','black');
		});
		$("span[id^='span_admin_']").click(function(){
			var warehouse_id=$(this).attr('id');
			warehouse_id=warehouse_id.substr('span_admin_'.length,warehouse_id.length-'span_admin_'.length);
			$("#select_admin_name_"+warehouse_id).show();
			$(this).hide();
		});		
		
		
		$("select[id^='select_admin_name_']").change(function(){
			var warehouse_id=$(this).attr('id');
			warehouse_id=warehouse_id.substr('select_admin_name_'.length,warehouse_id.length-'select_admin_name_'.length);	
			
			var admin_id=$(this).attr('value');
			
			Ajax.call('erp_warehouse.php?act=change_admin', 'warehouse_id=' + warehouse_id+ '&admin_id=' + admin_id, changeWarehouseAdminResponse, 'POST', 'JSON');
		
			function changeWarehouseAdminResponse(res)
			{
				if(res.error!=0)
				{
					alert(res.message);
				}
				else{
					window.location='erp_warehouse_manage.php?act=warehouse_list';
				}
			}
		});			
		
		
   });   
</script>
{/literal}
{include file="pagefooter.htm"}

